package com.hejjon.controller;

import com.hejjon.core.bean.ResponseResult;
import com.hejjon.core.bean.StrListBean;
import com.hejjon.core.controller.BaseController;
import com.hejjon.core.domain.entity.BusinessAttr;
import com.hejjon.core.enumer.DeleteFlagEnum;
import com.hejjon.domain.vo.BusiAttrTreeNodeVO;
import com.hejjon.domain.vo.BusinessAttrVO;
import com.hejjon.service.IBusinessAttrService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 888
 * 业务属性控制层
 * @author: cs
 * @date: 2025-04-17 14:28:58
 * @since: 1.0
 */
@RestController
@RequestMapping("/feature/busiAttr")
public class BusinessAttrController extends BaseController {

    @Resource
    private IBusinessAttrService businessAttrService;

    @PostMapping("/create")
    public ResponseResult create(@RequestBody BusinessAttr ba) {
        boolean b = businessAttrService.create(ba);
        return toResult(b, "业务属性保存成功!");
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody BusinessAttr ba) {
        boolean b = businessAttrService.update(ba);
        return toResult(b, "业务属性更新成功!");
    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody BusinessAttr ba) {
        List<BusinessAttrVO> list = businessAttrService.listByCategoryId(ba.getCategoryId());
        return success(list);
    }


    @PostMapping("/removeByIds")
    public ResponseResult removeByIds(@RequestBody StrListBean slb) {
        boolean b = businessAttrService.removeByIds(slb.getIds(), DeleteFlagEnum.YES.getCode());
        return toResult(b, "删除成功");
    }

    /**
     * 查询业务属性树形结构的数据
     *  业务属性分类
     *      业务属性子类
     *          属性1
     *          属性2
     * @return
     */
    @GetMapping("/listTree")
    public ResponseResult listTree(@RequestParam String featureId) {
        List<BusiAttrTreeNodeVO> busiAttrTreeNodeVOS = businessAttrService.listTree(featureId);
        return success(busiAttrTreeNodeVOS);
    }

}
